package com.cms.controller;

import com.cms.model.vo.SysUser;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("prototype")
public class BaseController {

    protected Logger log = LogManager.getLogger(getClass());

    /**
     * 登录用户名
     */
    public String getCurrentLoginName() {
        Subject currentUser = SecurityUtils.getSubject();
        SysUser user = currentUser.getPrincipals().oneByType(SysUser.class);
        return user.getUserLoginName();
    }

    /**
     * 登陆用户id
     * @return
     */
    public Integer getCurrentLoginId(){
        Subject currentUser = SecurityUtils.getSubject();
        SysUser user = currentUser.getPrincipals().oneByType(SysUser.class);
        return user.getUserId();
    }

    /**
     * 登录用户对象
     */
    public SysUser getCurrentUser() {
        Subject currentUser = SecurityUtils.getSubject();
        SysUser user = currentUser.getPrincipals().oneByType(SysUser.class);
        return user;
    }

}
